<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        window.onload=function()
        {
            //异步编程 文件操作 网络操作（ajax，request） 数据库操作
            //1s后控制台输出111 2s后输出222 3s后输出333
            //回调地狱
            /*
            setTimeout(() => {
                console.log(111);
                setTimeout(() => {
                    console.log(222);
                    setTimeout(() => {
                        console.log(333);
                    }, 3000);
                }, 2000);
            }, 1000);
            */
            function one()
            {
                setTimeout(() => {
                    console.log(111);
                    iterator.next()
                }, 1000);
            }

            function two()
            {
                setTimeout(() => {
                    console.log(222);
                    iterator.next()
                }, 1000);
            }

            function three()
            {
                setTimeout(() => {
                    console.log(333);
                    iterator.next()
                }, 1000);
            }

            function four()
            {
                setTimeout(() => {
                    console.log(444);
                    iterator.next()
                }, 1000);
            }

            function *gen()
            {
                yield one();
                yield two();
                yield three();
                yield four();
            }
            //调用生成器函数
            let iterator=gen();
            console.log(iterator.next());
            /*
            console.log(iterator.next());
            console.log(iterator.next());
            */
            //此方法可以解决回调地狱问题，让代码向下伸延而不是向右边
        };
    </script>
</head>
<body>
    
</body>
</html>